package com.empire.module.sporttery.controller.admin.football500yazcount;

import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.util.List;

import com.empire.framework.common.pojo.PageParam;
import com.empire.framework.common.pojo.PageResult;
import com.empire.framework.common.pojo.CommonResult;
import com.empire.framework.common.util.object.BeanUtils;
import static com.empire.framework.common.pojo.CommonResult.success;

import com.empire.framework.excel.core.util.ExcelUtils;

import com.empire.framework.apilog.core.annotation.ApiAccessLog;
import static com.empire.framework.apilog.core.enums.OperateTypeEnum.*;

import com.empire.module.sporttery.controller.admin.football500yazcount.vo.*;
import com.empire.module.sporttery.dal.dataobject.football500yazcount.Football500YazCountDO;
import com.empire.module.sporttery.service.football500yazcount.Football500YazCountService;

@Tag(name = "管理后台 - 亚盘实时表统计")
@RestController
@RequestMapping("/sporttery/football500-yaz-count")
@Validated
public class Football500YazCountController {

    @Resource
    private Football500YazCountService football500YazCountService;

    @PostMapping("/create")
    @Operation(summary = "创建亚盘实时表统计")
    @PreAuthorize("@ss.hasPermission('sporttery:football500-yaz-count:create')")
    public CommonResult<Integer> createFootball500YazCount(@Valid @RequestBody Football500YazCountSaveReqVO createReqVO) {
        return success(football500YazCountService.createFootball500YazCount(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新亚盘实时表统计")
    @PreAuthorize("@ss.hasPermission('sporttery:football500-yaz-count:update')")
    public CommonResult<Boolean> updateFootball500YazCount(@Valid @RequestBody Football500YazCountSaveReqVO updateReqVO) {
        football500YazCountService.updateFootball500YazCount(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除亚盘实时表统计")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('sporttery:football500-yaz-count:delete')")
    public CommonResult<Boolean> deleteFootball500YazCount(@RequestParam("id") Integer id) {
        football500YazCountService.deleteFootball500YazCount(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得亚盘实时表统计")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('sporttery:football500-yaz-count:query')")
    public CommonResult<Football500YazCountRespVO> getFootball500YazCount(@RequestParam("id") Integer id) {
        Football500YazCountDO football500YazCount = football500YazCountService.getFootball500YazCount(id);
        return success(BeanUtils.toBean(football500YazCount, Football500YazCountRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得亚盘实时表统计分页")
    @PreAuthorize("@ss.hasPermission('sporttery:football500-yaz-count:query')")
    public CommonResult<PageResult<Football500YazCountRespVO>> getFootball500YazCountPage(@Valid Football500YazCountPageReqVO pageReqVO) {
        PageResult<Football500YazCountDO> pageResult = football500YazCountService.getFootball500YazCountPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, Football500YazCountRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出亚盘实时表统计 Excel")
    @PreAuthorize("@ss.hasPermission('sporttery:football500-yaz-count:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportFootball500YazCountExcel(@Valid Football500YazCountPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<Football500YazCountDO> list = football500YazCountService.getFootball500YazCountPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "亚盘实时表统计.xls", "数据", Football500YazCountRespVO.class,
                        BeanUtils.toBean(list, Football500YazCountRespVO.class));
    }

}